# Coordination

library(ggplot2)

# coord_cartesian()----
p <- qplot(disp, wt, data = mtcars) + geom_smooth()
p
p + scale_x_continuous(limits = c(325, 500))
p + coord_cartesian(xlim = c(325, 500))  

d <- ggplot(diamonds, aes(carat, price)) + 
  stat_bin2d(bins = 25, colour = "grey70") +
  theme(legend.position = "none")
d
d + scale_x_continuous(limits = c(0, 2))
d + coord_cartesian(xlim = c(0, 2))

# Reverse coord----
qplot(displ, cty, data = mpg) + geom_smooth()
qplot(cty, displ, data = mpg) + geom_smooth()
qplot(displ, cty, data = mpg) + geom_smooth() + coord_flip()

# Transform----
qplot(carat, price, data = diamonds, log = "xy") +
  geom_smooth(method = "lm")
library(scales)
last_plot() + coord_trans(x = exp_trans(10), y = exp_trans(10))

# Pie----
pie <- ggplot(mtcars, aes(x = factor(1), fill = factor(cyl))) +
  geom_bar(width = 1)
pie  # Stacked bar
pie + coord_polar(theta = "y")  # Pie
pie + coord_polar()  # Circle
